package com.tanhua.sso.controller;


import com.tanhua.sso.service.UserInfoService;
import com.tanhua.common.vo.ErrorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;
//新用户信息接口
@RestController
@RequestMapping("user/")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    //信息上传到数据库
    @PostMapping("loginReginfo")
    public ResponseEntity<Object> saveLoginReginfo(@RequestBody Map<String, String> param) {
        ErrorResult errorResult = userInfoService.saveLoginReginfo(param);
        if (errorResult == null) return null;
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }

    //存储图片到oss与人脸校验
    @PostMapping("loginReginfo/head")
    public ResponseEntity<Object> saveLogo(@RequestParam("headPhoto") MultipartFile file) {
        ErrorResult errorResult = null;
        try {
            errorResult = userInfoService.saveLogo(file);
            if (errorResult == null) return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }
}